package org.javaboy.demo;

import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author Lyh
 * @date 2024/2/22 1:29
 * @desciption:
 */
public class Demo02 {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
        //我们关于Bean的配置，都会被先解析为beanDefinition
        RootBeanDefinition beanDefinition = new RootBeanDefinition();
        beanDefinition.setBeanClass(Animal.class);
        MutablePropertyValues values = new MutablePropertyValues();
        values.add("category","猫科");
        // 这个是给Animal中各个属性设置值的
        beanDefinition.setPropertyValues(values);
        ctx.registerBeanDefinition("parent", beanDefinition);
        GenericBeanDefinition cbd = new GenericBeanDefinition();
        cbd.setBeanClass(Cat.class);
        MutablePropertyValues pvalues = new MutablePropertyValues();
        pvalues.add("name","小花");
        pvalues.add("color","五颜六色");
        cbd.setPropertyValues(pvalues);
        cbd.setParentName("parent");
        ctx.registerBeanDefinition("child",cbd);
        ctx.refresh();
        Cat cat = ctx.getBean(Cat.class);
        System.out.println("cat = " + cat);
    }
}
